package 综合练习;

import java.util.Arrays;
import java.util.Comparator;

public class girlfriendtest {
    public static void main(String[] args) {
        //定义数组并储存一些对象，利用sort方法排序
        //要求1:属性有名字，年龄，身高
        //要求2:按照年龄排序，年龄一样，按身高排序，身高一样，按名字首字母排序
        girlfriend g1=new girlfriend("zhangsan",12,175);
        girlfriend g2=new girlfriend("lisi",13,176);
        girlfriend g3=new girlfriend("wangwu",13,175);
        girlfriend g4=new girlfriend("zhaoliu",14,177);
        girlfriend g5=new girlfriend("xiaoer",14,177);
        girlfriend []arr={g1,g2,g3,g4,g5};
        Arrays.sort(arr, (o1, o2) -> {
            if(o1.getAge()!=o2.getAge()){
            return o1.getAge()-o2.getAge();
            } else if (o1.getTall() != o2.getTall()) {
                return o1.getTall()-o2.getTall();
            }
            return o1.getName().compareTo(o2.getName());
        });
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i].getName()+","+arr[i].getAge()+","+arr[i].getTall());
        }
    }
}
